package com.logisticsmanagement.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.logisticsmanagement.utils.GlobelValue;
import com.logisticsmanagement.utils.JsonUtls;
import com.logisticsmanagement.vo.BaseResponse;

/**
 * Servlet implementation class Route
 */
@WebServlet("/Route")
public class RouteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		JSONObject jsonObject = JsonUtls.JSONObject(request);
		String requetsMothod = jsonObject.getString(GlobelValue.REQUEST_METHOD);
		if(requetsMothod == null || "".equals(requetsMothod)){
			//request not valid
			JSONObject responseJson = JSONObject.fromObject(new BaseResponse(GlobelValue.ERROR_LOST_REQUEST_MOTHOD,GlobelValue.ERROR_LOST_REQUEST_MOTHOD_DESCRIPTION));
			response.getWriter().write(responseJson.toString());
		}
		else if(requetsMothod.equals(GlobelValue.METHOD_ADD)){//add a route node
			
		}else if(requetsMothod.equals(GlobelValue.METHOD_GETINFO)){//get one route  information of this city,this method could result in some bad things,such as some route will be a cycle
			
		}else if(requetsMothod.equals(GlobelValue.METHOD_DELETE)){//delete one route ,this method could result in some bad thing,such as some city will not connect other city
			
		}else{
			//request method not exit
			JSONObject responseJson = JSONObject.fromObject(new BaseResponse(GlobelValue.ERROR_NOT_EXIST_REQUEST_MOTHOD,GlobelValue.ERROR_NOT_EXIST_REQUEST_MOTHOD_DESCRIPTION));
			response.getWriter().write(responseJson.toString());
		}
	}
}
